package com.example.demo.dao;

import com.example.demo.bean.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author Jim Chen
 * @date 2021-04-15
 */
@Mapper
@Repository
public interface UserDao {

    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "mark", column = "mark")
    })
    @Select("select * from user")
    List<User> findAll();


    @Select("select * from user where id = #{id}")
    User getById(Integer id);

    @Options(useGeneratedKeys = true, keyProperty = "id") // 设置主键
    @Insert("insert into user (name, mark) values (#{name}, #{mark})")
    Integer create(User user);

    @Update("update user set name = #{name}, mark = #{mark} where id = #{id}")
    int update(User user);

    @Delete("delete from user where id = #{id}")
    int delete(Integer id);

}
